package cn.snowheart.observer.weather.jvm.display;

import cn.snowheart.observer.weather.jvm.weather.WeatherData;

import java.util.Observable;
import java.util.Observer;

/**
 * @author liuwanxiang
 * @version 2019/06/24
 */
public class StatisticsDisplay implements Observer, DisplayElement {

    private int data;

    @Override
    public void display() {
        System.out.println("show statistics data..." + data);
    }

    @Override
    public void update(Observable o, Object arg) {
        // 推模式
        if (arg != null) {
            this.data = (int) arg;
            display();
        } else {
            // 拉模式
            if (o instanceof WeatherData) {
                WeatherData weatherData = (WeatherData) o;
                this.data = weatherData.getData();
            }
        }
    }
}
